\encoding{utf8}
\name{cphsoc_stata_export}
\alias{cphsoc_stata_export}
\title{Convert an R data.frame to Stata format}
\description{
  Write an R data.frame as a set of a raw csv-file and a stata do-file.
}
\usage{cphsoc_stata_export(df,stata_do_path,infile_data_path,stata_csv_path,
        renamed_vars_path,na='',target_enc='',stata_dta_path,dta_replace=FALSE)
}
\arguments{
  \item{df}{data.frame, data to convert.}
  \item{stata_do_path}{character, name of the do-file}
  \item{infile_data_path}{character, path to data, is written into the do-file}
  \item{renamed_vars_path}{character, name of file where renaming is reported}
  \item{na}{character, how to represent NA (missing values)}
  \item{target_en}{character, encoding of target files, if reencoding is needed (default is no reencoding)}
  \item{stata_dta_path}{character, path where to save dta-file when running do-file (is written into do-file)}
  \item{dta_replace}{logical, add 'replace' to Stata do-file (an existing dta file will be automatically overwritten when the do-file is run)}
}
\value{
  A character vector reporting the files saved.
  
  A csv-file, a do-file and possibly a report of renamed variables are saved.
}
\details{
  The Stata format has a number of limitations compared to SPSS and R formats: 
  
  Variable names: Variable names can be up to 32 characters, they must not contain various special characters that are perfectly legal in SPSS and R.
  Stata variable names can contain non-ascii characters like Danish letters but they cannot be the first character. Therefore all names are adjusted to these limitations.
  
  Number of variables: The basic license which is the most common only 2027 variables are allowed, therefore if this is an issue datasets that exceed this limit must be divided into two datasets.
  This function does not do that (we could consider this for a future version).
  
  String variables special issues: String variables that contain data with double quotes has proven to not convert correctly, therefore all double quotes within string values are replaced with single quotes.
}
\seealso{
  \code{\link{cphsoc_convert_from_spss}}
}
\author{Finn Sandø}
\keyword{cphsoc}
